﻿using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Workflow_Core_API.Persisted
{
    /// <summary>
    /// 流程业务实例表,与 PersistedWorkflow一对一关系
    /// </summary>
    [Table("WorkflowInstance")]
    public class PersistedWorkflowInstance
    {
        public int Id { get; set; }

        /// <summary>
        /// 流程引擎实例ID
        /// </summary>
        [MaxLength(50)]
        public string WorkflowInstanceId { get; set; } = null!;

        /// <summary>
        /// 流程定义ID
        /// </summary>
        [MaxLength(200)]
        public string WorkflowDefinitionId { get; set; }

        /// <summary>
        /// 流程实例标题
        /// </summary>
        [MaxLength(200)]
        public string Title { get; set; } = null!;

        /// <summary>
        /// 流程表单内容
        /// </summary>
        [Column(TypeName = "json")]
        public string? FormFields { get; set; }

        /// <summary>
        /// 发起人
        /// </summary>
        public long ApplicantUserId { get; set; }
        /// <summary>
        /// 发起人姓名
        /// </summary>
        [MaxLength(50)]
        public string ApplicantUserName { get; set; } = null!;

        /// <summary>
        /// 申请时间
        /// </summary>
        public DateTime ApplicantTime { get; set; } = DateTime.Now;

        /// <summary>
        /// 完成时间
        /// </summary>
        public DateTime? CompleteTime { get; set; }

        /// <summary>
        /// 当前流程节点Id
        /// </summary>
        [MaxLength(50)]
        public string? CurrentStepId { get; set; }

        /// <summary>
        /// 当前流程节点名称
        /// </summary>
        [MaxLength(50)]
        public string? CurrentStepName { get; set; }

        /// <summary>
        /// 当前审批人(多个以逗号隔开)
        /// </summary>
        [MaxLength(200)]
        public string? CurrentAuditUsers { get; set; }

        /// <summary>
        /// 当前审核人ID(多个以逗号隔开)
        /// </summary>
        [MaxLength(200)]
        public string? CurrentAuditUserIds { get; set; }

        /// <summary>
        /// 驳回到的节点
        /// </summary>
        [MaxLength(50)]
        public string? RejectToStepId { get; set; }

        /// <summary>
        /// 实例状态
        /// </summary>
        public WorkflowInstanceStatus Status { get; set; }
    }

    /// <summary>
    /// 实例状态
    /// </summary>
    public enum WorkflowInstanceStatus
    {
        [Description("草稿")]
        Draft = 0,
        [Description("发起")]
        WorkflowStart = 1,
        [Description("处理中")]
        Processing = 2,
        [Description("已完成")]
        Completed = 3,
        [Description("已废弃")]
        Terminate = 4,
        [Description("异常")]
        Exception = 5
    }
}
